package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.entity.vo.UserVo;
import com.example.demo.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2021-02-20 11:05:14
 */
@Controller
@RequestMapping("user")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    @RequestMapping
    public String index() {
        return "index";
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @ResponseBody
    public UserVo selectOne(@PathVariable Integer id) {
        return this.userService.queryById(id);
    }


    @GetMapping("/list")
    @ResponseBody
    public List<User> list() {
        return this.userService.list();
    }

}